package com.yin.myproject.zk;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author Eason
 * @create 2018-04-11 17:08
 **/
public class DistributedLockDemo {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                DistributedLockExample lockExample = new DistributedLockExample("192.168.212.104:2181","test");
                try {
                    lockExample.lock();
                    System.out.println(1);
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    lockExample.unlock();
                }
            }
        });
    }
}
